<!DOCTYPE html>
<html>

{include file='public/header'}
<style>
    .layui-layer-page .layui-layer-content {
        overflow: visible;
    }
</style>

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="javascript:void(0)">首页</a>
            <a href="javascript:void(0)">短剧推广</a>
            <a><cite>自定义收费设置</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" id="reload" title="刷新">
            <i class="layui-icon" style="line-height:30px"><i class="iconfont">&#xe6aa;</i></i>
        </a>
    </div>
    <div class="x-body">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">充值模板名称：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" placeholder="请输入充值模板名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <button class="layui-btn" style="margin-left: 10px;" lay-submit lay-filter="searchList">搜索</button>
                <button type="reset" id="resetList" class="layui-btn layui-btn-primary">重置</button>
            </form>
        </div>
        <table id="recharge" lay-filter="recharge"></table>
    </div>
    <script type="text/html" id="toolbarDemo">
        {{#  
            if(is_distributor !== 1 && is_branch_office_manage!==1){
                return `
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
                </div>`
            }
        }}
    </script>
    <script type="text/html" id="tbBar">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="copy">复制</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
        {{#  
            if(is_distributor !== 1 && is_branch_office_manage!==1){
                return `
               
                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="copy">复制</a>
                <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>`
            }else{
                return `
                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                `
            }
        }}
    </script>
    <script>
        let params = {
            elem: '#recharge'
            , toolbar: '#toolbarDemo'
            , url: '/cps/customRechargeTemplate/list' //数据接口
            , id: 'recharge'
            , page: true
            , limit: 15
            , cols: [[ //表头
                { field: 'id', title: 'ID', width: 80, sort: true, align: 'center' }
                , { field: 'name', title: '充值模板名称', align: 'center', width: 200 }
                // , { field: 'type', title: '充值模板名称', align:'center', width: 160 }
                , {
                    title: '充值模板类型111', templet: function (d) {
                        return d.type == 1 ? '低充' : d.type == 2 ? '中充' : '高充'
                    }, align: 'center', width: 120
                }
                // , { field: 'type', title: '充值模板类型', align: 'center', width: 100 }
                , { field: 'responsibility_person_name', title: '负责人', align: 'center', width: 100 }
                , { field: 'video_name', title: '短剧名称', align: 'center', width: 200 }
                , { field: 'use_link', title: '使用链接', align: 'center' }

                , {
                    field: 'created_at', title: '创建时间', align: 'center', width: 170,
                }
                , {
                    field: 'updated_at', title: '更新时间', width: 170, align: 'center'
                }
                , { toolbar: '#tbBar', align: 'center', title: '操作', width: 180 }
            ]]
        }
        tableList(params)

        let selectParams = {
            url: '/cps/video/select?is_shelves=0',
            selected: [],
            tips: '选择短剧',
            name: 'video_id',
            field_id: 'id',
            field_Name: 'name',
            elem: '#pMenu'

        }

        let rechargeTemplate = `
                    <div class="x-body batch" >
                        <form class="layui-form" lay-filter="rechargeTemplate">
                            <div class="layui-form-item">
                                <label class="layui-form-label">
                                    <span class="x-red">*</span>选择剧名
                                </label>
                                <div id="pMenu" style="width:300px;flex:1"></div>
                            </div>
                         
                        </form>
                    </div>
                    <div class="x-body batch" >
                        <form class="layui-form" lay-filter="rechargeTemplate">
                            <div class="layui-form-item" style='display: flex;'>
                                <label class="layui-form-label"><span class="x-red">*</span>模板名称
                                    
                                </label>
                                <input type="text" style='width:60%' name="name" id="name" placeholder="充值模板名称" required="required"
                                 lay-verify="required" autocomplete="off" class="layui-input" value="" />
                            </div>
                         
                        </form>
                    </div>
                `

        var video_id;

        layui.use('table', function () {
            var table = layui.table;
            table.on('toolbar(recharge)', function (obj) {
                var event = obj.event;
                if (event === 'add') {
                    x_admin_show('添加', './info.html', 1250, 650);
                    // sessionStorage.clear()
                    sessionStorage.removeItem('recharged_content')
                    sessionStorage.removeItem('not_recharged_content')
                    sessionStorage.removeItem('message')
                }
            });
            table.on('tool(recharge)', function (obj) {
                var event = obj.event;
               
                let {  type, responsibility_person_id, charge_type, interval_recharge, not_recharged_content, pay_amount, recharged_content, sort } = obj.data;
                if (event === 'del') {
                    DeleteAjax('/cps/custom_recharge_template/delete', { id: obj.data.id }, 'recharge')
                } else if (event === 'edit') {
                    x_admin_show('编辑', `./info.html?company_id=${obj.data.company_id}&id=${obj.data.id}`, 1250, 650);
                    // sessionStorage.clear()
                    sessionStorage.removeItem('recharged_content')
                    sessionStorage.removeItem('not_recharged_content')
                    sessionStorage.removeItem('message')
                } else if (event === 'copy') {
                    // 
                    // AnyAjax(`<div id="pMenu" style="width:100%;"></div>`, '/cps/recharge/add', { name, type, not_recharged_content, recharged_content }, 'recharge')
                    //     let { name, type } = obj.data;
                    //     let content = `
                    //     <div id="pMenu" style="width:80%;"></div>
                    // `;
                    //     layer.open({
                    //         type: 1,
                    //         title: '选择剧名22',
                    //         btn: ['确定', '取消'],
                    //         maxHeight: '500',
                    //         content,
                    //         success: function () {
                    //             // xmSelectA(xmSelectGetAuthorizersOption)
                    //             selectN(selectParams)
                    //         },
                    //         yes: function (layMask) {
                    //             console.log(layMask);
                    //             // AnyAjax(``, { name, type }, 'recharge')
                    //         }
                    //     });


                    layerOpen({
                        type: 1,
                        title: '选择剧名',
                        content: rechargeTemplate,

                        success: function () {
                            selectN(selectParams)
                        },
                        yes: function (data, layMask) {

                            let name= $('#name').val()
                            return new Promise((resolve) => {
                                Ajax('/cps/customRechargeTemplate/add',
                                    { name, type, charge_type, interval_recharge, not_recharged_content, pay_amount, recharged_content, sort, video_id }
                                ).then(result => {
                                    tableList(params)
                                    resolve()
                                });
                            })

                        }
                    })
                }
            });

        });

        function infoSelectN(option, value) {
            video_id = value
        }


    </script>
</body>

</html>